<script lang="ts" setup>
import type { VbenFormProps } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { Page } from '@vben/common-ui';
import { Button, Modal } from 'ant-design-vue';

import { useVbenVxeGrid } from '#/adapter/vxe-table';

import { useRouter } from 'vue-router';

const router = useRouter();

interface RowType {
  category: string;
  color: string;
  id: string;
  price: string;
  productName: string;
  releaseDate: string;
}

const formOptions: VbenFormProps = {
  // 默认展开
  collapsed: false,
  schema: [
    {
      component: 'Input',
      defaultValue: '',
      fieldName: 'category',
      label: 'ID',
    },
    {
      component: 'Input',
      fieldName: 'productName',
      label: '日期',
    },
    {
      component: 'Input',
      fieldName: 'productName',
      label: '权限组名称',
    },
  ],
  // 控制表单是否显示折叠按钮
  showCollapseButton: true,
  // 按下回车时是否提交表单
  submitOnEnter: false,
};

const gridOptions: VxeGridProps<RowType> = {
  checkboxConfig: {
    highlight: true,
    labelField: 'name',
  },
  columns: [
    { field: 'id', title: '权限ID' },
    {
      field: 'name',
      title: '权限组名称',
    },
    { field: 'description', title: '权限描述' },
    {
      field: 'action',
      fixed: 'right',
      slots: { default: 'action' },
      title: '操作',
      width: '240',
    },
  ],
  height: 'auto',
  keepSource: false,
  pagerConfig: {},
  data: [
    {
      id: '1',
      name: '权限组1',
      description: '权限描述1',
    },
    {
      id: '2',
      name: '权限组2',
      description: '权限描述2',
    },
    {
      id: '3',
      name: '权限组3',
      description: '权限描述3',
    },
  ],
};

const [Grid] = useVbenVxeGrid({ formOptions, gridOptions });

function routerPush(name: string, id: number) {
  // 这里就是路由跳转，也可以用path
  router.push({ name: name, params: { id } });
}

function handleDelete(id: number) {
  Modal.confirm({
    title: '确认删除',
    content: '是否确认删除该员工？',
    onOk() {
      console.log('ok');
    },
    onCancel() {
      console.log('cancel');
    },
  });
}
</script>

<template>
  <Page auto-content-height>
    <Grid>
      <template #action="{ row }">
        <Button type="link">权限分配</Button>
      </template>

      <template #toolbar-tools>
        <Button
          class="mr-2"
          type="primary"
          @click="$router.push({ name: 'StaffAuthCreate' })"
          >新建</Button
        >
      </template>
    </Grid>
  </Page>
</template>
